<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.6.8/css/layui.min.css"   />
    <link rel="stylesheet" href="../../res/css/mz.css" />
    <script src="https://cdn.staticfile.org/layui/2.6.8/layui.min.js" ></script>
    <script src="../../res/js/mz.common.js"></script>
    <script src="../../res/js/mz.list.js"></script>
    <style>
        .layui-input-inline .layui-input{display: inline-block; width: 200px;}
        .operations a {margin-top: 5px;}
    </style>
</head>
<body>

<div style=" margin: 10px auto;">
    <a class="layui-btn layui-btn-success layui-btn-sm" href="edit.html"><i class="layui-icon layui-icon-addition"></i>新增</a>
    <div class="layui-input-inline">
        <select id="sent" class="layui-input">
            <option value="%">全部(发送)</option>
            <option value="1">待发送</option>
            <option value="2">已发送</option>
        </select>
    </div>
    <div class="layui-input-inline">
        <select id="platform" class="layui-input">
            <option value="%">全部(平台)</option>
            <option value="1">荆州</option>
            <option value="2">十堰</option>
            <option value="3">洪山</option>
            <option value="4">东湖高新</option>
            <option value="5">新洲</option>
            <option value="6">洪湖</option>
            <option value="7">江陵</option>
            <option value="8">竹山</option>
            <option value="9">竹溪</option>
        </select>
    </div>
    <div class="layui-input-inline">
        <input id="key" type="text" class="layui-input" placeholder="输入项目编号" />
        <button onclick="query()" class="layui-btn layui-btn-success layui-btn-sm"><i class="layui-icon layui-icon-search"></i>查询</button>
    </div>
</div>

<div style=" margin: 10px auto;">
    <table id="table_view"></table>
</div>

<script type="text/html" id="operationDemo">
    <div class="operations" style="text-align: center;">
        <a class="layui-btn layui-btn-success layui-btn-xs" lay-event="preview_announcement">预览公告</a><br>
        <a class="layui-btn layui-btn-success layui-btn-xs" lay-event="release_announcement">发布公告</a><br>
        <a class="layui-btn layui-btn-success layui-btn-xs" lay-event="release_project">发布项目</a>
    </div>
</script>

<script>

    var announce_types = {"1": "资格预审公告", "2": "招标公告（公开招标、邀请招标）", "3": "竞争性谈判（竞争性磋商、询价采购）公告",
        "4": "单一来源公示", "5": "中标(成交结果)公告", "6": "更正公告", "7": "终止公告", "8": "需求公示(征询意见)"};

    var data_platforms = {"1": "荆州", "2": "十堰", "3":"洪山", "4":"东湖高新", "5":"新洲", "6":"洪湖", "7":"江陵", "8":"竹山", "9":"竹溪"};

    var sents = {"1":"待发送", "2":"已发送"};

    var field_setting = [
        {title: '项目编号', width: 300, field: 'project_num', type: 'text'},
        {title: '公告标题', field: 'title', type: 'text'},
        {title: '公告类型', field: 'announce_type', templet: function (d) { return announce_types[d.announce_type]  }},
        {title: '所属平台', width: 100, field: 'data_platform', templet: function (d) { return data_platforms[d.data_platform]  }},
        {title: '发送状态', width: 100, field: 'sent', templet: function (d) { return sents[d.sent]  }},
        {title: '更新时间', width: 200, field: 'modified', type: 'text'},
    ];

    // field_setting.unshift({type: 'checkbox', fixed: 'left'});

    field_setting.push({fixed: 'right', title: '操作', width: 100, align:'center', toolbar: '#operationDemo'});

    var listObj = new MZList({
        elem: '#table_view',
        url: base_url + '/query_announcement',  //数据接口
        where: {
            project_num: '%',
            sent: '%',
            data_platform: '%',                        //自定义查询字段
        },
        cols: [field_setting],
        toolbarEvents: {
            preview_announcement: function (d) {
                if(d.announce_type == 5){
                    location.href = './preview1.html?id=' + d.announce_id + '&pid=' + d.project_id;
                }else{
                    location.href = './preview.html?id=' + d.announce_id + '&pid=' + d.project_id;
                }
            },
            release_announcement: function (d) {
                layer.confirm('确认发布公告?', {icon: 3, title:'ALERT'}, function(index){
                    layer.close(index);
                    layui.$.post(base_url + '/release_announcement', {announce_id: d.announce_id}, function (res) {
                        if(res.content){
                            layer.msg('发布成功');
                            query();
                        }else{
                            layer.msg('发布失败：' + (res.message || ''));
                        }
                    })
                });
            },
            release_project: function (d) {
                layer.confirm('确认发布项目?', {icon: 3, title:'ALERT'}, function(index){
                    layer.close(index);
                    layui.$.post(base_url + '/release_project', {project_id: d.project_id}, function (res) {
                        if(res.content){
                            layer.msg('发布成功');
                            query();
                        }else{
                            layer.msg('发布失败：' + (res.message || ''));
                        }
                    })
                });
            }
        }
    });

    function query() {
        var key = layui.$("#key").val();
        key = '%' + key + '%';
        //根据条件查询，需要数据接口查询语句有如下参数（eg : ‘title’）
        listObj.reload( {where : {project_num: key, sent: layui.$("#sent").val(), data_platform: layui.$("#platform").val()}} )
    }

</script>

</body>
</html>
